<template>
  <a-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :destroyOnClose="true"
    cancelText="关闭"
    :footer="null"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24"> </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" size="small" type="primary" icon="plus">新增</a-button>
      </div>

      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          :scroll="{ x: true }"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange"
        >
          <span slot="action" slot-scope="text, record">
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a>删除</a>
                  </a-popconfirm>
            <!-- <a-dropdown>
              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
              <a-menu slot="overlay">
                <a-menu-item>
                  <a @click="handleDetail(record)">详情</a>
                </a-menu-item>
                <a-menu-item>

                </a-menu-item>
              </a-menu>
            </a-dropdown> -->
          </span>
        </a-table>
      </div>

      <ex-tender-file-set-variable-modal ref="modalForm" @ok="modalFormOk"></ex-tender-file-set-variable-modal>
    </a-card>
  </a-modal>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ExTenderFileSetVariableModal from './modules/ExTenderFileSetVariableModal'
import { getAction } from '@/api/manage'

export default {
  name: 'ExTenderFileSetVariableList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ExTenderFileSetVariableModal,
  },
  props: {
    projectId: {
      default: '',
    },
    sectionId: {
      default: '',
    },
  },
  data() {
    return {
      description: '招标文件定义变量管理页面',
      title: '变量',
      visible: false,
      confirmLoading: false,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: 'key',
          align: 'center',
          dataIndex: 'columnKey',
        },
        {
          title: '名称',
          align: 'center',
          dataIndex: 'columnName',
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: 'columnType',
        },
        {
          title: '长度',
          align: 'center',
          dataIndex: 'columnSize',
        },
         {
          title: '是否开标显示',
          align: 'center',
          dataIndex: 'ifShow_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exTenderFileSetVariable/exTenderFileSetVariable/list',
        delete: '/exTenderFileSetVariable/exTenderFileSetVariable/delete',
        deleteBatch: '/exTenderFileSetVariable/exTenderFileSetVariable/deleteBatch',
        exportXlsUrl: '/exTenderFileSetVariable/exTenderFileSetVariable/exportXls',
        importExcelUrl: 'exTenderFileSetVariable/exTenderFileSetVariable/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'columnKey', text: '对应key(C01)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'columnName', text: '对应名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'columnType', text: '类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'columnSize', text: '长度', dictCode: '' })
      this.superFieldList = fieldList
    },
    loadData(arg, pageSize = 10) {
      // 如果传入参数为1，则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1;
      }
    
      // 获取查询条件并设置分页参数
      var params = this.getQueryParams();
      params.projectId = this.projectId;
      params.sectionId = this.sectionId;
      params.current = this.ipagination.current; // 明确设置当前页码
      params.pageSize = pageSize;
    
      // 设置加载状态
      this.loading = true;
    
      // 发起请求
      return getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            // 处理返回的数据
            this.dataSource = res.result.records || res.result || []; // 防止空值
            this.ipagination.total = res.result.total || 0; // 防止未返回total字段
            return this.dataSource;
          } else {
            // 请求失败，显示错误信息并清空数据
            this.$message.warning(res.message);
            this.dataSource = [];
            this.ipagination.total = 0;
          }
        })
        .finally(() => {
          // 请求完成后关闭加载状态
          this.loading = false;
        });
    },

    handleAdd: function () {
      if (this.projectId == '') {
        return
      }
      this.$refs.modalForm.add({ projectId: this.projectId, sectionId: this.sectionId })
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    show() {
      this.loadData();
      this.visible = true
    },
    handleOk() {

    },
    handleCancel() {
      this.visible = false;
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
